package com.huluobo.a2111douyindemo.live;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.mvvm_base.mvvm.base.viewmodel.BaseViewModel;
import com.huluobo.mvvm_base.mvvm.bean.FollowBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.GiftBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.Money;
import com.huluobo.mvvm_base.mvvm.net.Const;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/3/5.
 */
public class LiveViewModel extends BaseViewModel<LiveRepo> {

    MutableLiveData<FollowBeanResult> followSuccess = new MutableLiveData<>();

    MutableLiveData<String> followFailed = new MutableLiveData<>();

    MutableLiveData<FollowBeanResult> noFollowSuccess = new MutableLiveData<>();

    MutableLiveData<String> noFollowFailed = new MutableLiveData<>();

    MutableLiveData<GiftBeanResult> getGiftSuccess = new MutableLiveData<>();

    MutableLiveData<String> getGiftFailed = new MutableLiveData<>();

    MutableLiveData<Money> getMoneySuccess = new MutableLiveData<>();

    MutableLiveData<String> getMoneyFailed = new MutableLiveData<>();

    public void followAuth(String authName) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME, authName);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.followAuth(body, followSuccess, followFailed);
    }

    public void noFollowAuth(String authName) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTH_NAME, authName);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.noFollowAuth(body, noFollowSuccess, noFollowFailed);
    }

    public void getGiftList() {
        repo.getGiftList(getGiftSuccess, getGiftFailed);
    }

    public void getUserMoney(String username) {
        repo.queryUserMoney(username, getMoneySuccess, getMoneyFailed);
    }

    public void updateUserMoney(Money money) {
        repo.updateUserMoney(money);
    }

    public LiveViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected LiveRepo createRepo() {
        return new LiveRepo();
    }
}
